import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'

Vue.use(VueRouter)

const routes = [
	{
		path: '/login',
		name: 'Login',
		component: () => import('@/views/login')
	},
	{
		path: '/',
		name: 'Index',
		component: () => import('@/views'),
		children: [
			{
				path: '/user',
				name: 'UserIndex',
				component: () => import('@/views/ums/user')
			},
			{
				path: '/role',
				name: 'RoleIndex',
				component: () => import('@/views/ums/role')
			},
			{
				path: '/brand',
				name: 'BrandIndex',
				component: () => import('@/views/pms/brand')
			},
			{
				path: '/roleUser',
				name: 'RoleUser',
				component: () => import('@/views/ums/role/userList')
			},
			{
				path: '/resource',
				name: 'ResourceIndex',
				component: () => import('@/views/ums/resource/index')
			},
			{
				path: '/roleResource',
				name: 'RoleResource',
				component: () => import('@/views/ums/role/resourceList')
			}
		]
	},
	
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
// 定义白名单
const white = ['Login']
router.beforeEach((to, from, next) => {
	for(const index in white){
		if(white[index] === to.name){
			next()
			return
		}
	}
	if(store.getters.GET_TOKEN) {
		next()
		return
	}
	next('/login')
})
export default router
